package com.artezio.buyndrive.service.impl;

import com.artezio.buyndrive.service.CapchaService;
import net.tanesha.recaptcha.ReCaptchaImpl;
import net.tanesha.recaptcha.ReCaptchaResponse;
import javax.servlet.http.HttpServletRequest;

/**
 * User: spolyakov
 * Date: 27.07.12
 * Time: 13:18
 */
public class CapchaServiceImpl implements CapchaService{

    public boolean isHuman(HttpServletRequest servletRequest) {
            String remoteAddr = servletRequest.getRemoteAddr();
            ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
            reCaptcha.setPrivateKey("6LcvSdQSAAAAAKMqLAmy4P5Xu4Oyf7oeFyZLxK4k");

            String challenge = servletRequest.getParameter("recaptcha_challenge_field");
            String uresponse = servletRequest.getParameter("recaptcha_response_field");
            ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer(remoteAddr, challenge, uresponse);

        return reCaptchaResponse.isValid();
    }
}
